package com.woniuxy.ptapp.common.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.woniuxy.commons.util.Result;
import com.woniuxy.ptapp.common.exception.EnumExceptionCode;
import com.woniuxy.ptapp.common.exception.WoniuxyException;
import com.woniuxy.userapp.client.CoachClient;
import com.woniuxy.userapp.client.StudentClient;
import com.woniuxy.userapp.client.VenueClient;
import com.woniuxy.userapp.client.param.CoachInfo;
import com.woniuxy.userapp.client.param.StudentInfo;
import com.woniuxy.userapp.client.param.VenueInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;

@Component
public class FinAccountIdByMessageId {

    @Resource
    VenueClient venueClient;
    @Resource
    CoachClient coachClient;
    @Resource
    StudentClient studentClient;
    public Integer findVenueAccountId(Integer venueId){
        Result<Integer> accountIdByVenueId = venueClient.findAccountIdByVenueId(venueId);
        if(accountIdByVenueId==null||accountIdByVenueId.getCode()==500||accountIdByVenueId.getData()==null){
            throw new WoniuxyException(EnumExceptionCode.ThereIsNoVenue.getCode(),EnumExceptionCode.ThereIsNoVenue.getMessage());
        }
        return accountIdByVenueId.getData();
    }

    public Integer findCoachAccountId(Integer coachId){
        Result<Integer> accountIdByCoachId = coachClient.findAccountIdByCoachId(coachId);
        if(accountIdByCoachId==null||accountIdByCoachId.getCode()==500||accountIdByCoachId.getData()==null){
            throw new WoniuxyException(EnumExceptionCode.ThereIsNoCoach.getCode(),EnumExceptionCode.ThereIsNoCoach.getMessage());
        }
        return accountIdByCoachId.getData();
    }

    public Integer findStudentAccountId(Integer studentId){
        Result<Integer> accountIdByStudentId = studentClient.findAccountIdByStudentId(studentId);
        if(accountIdByStudentId==null||accountIdByStudentId.getCode()==500||accountIdByStudentId.getData()==null){
            throw new WoniuxyException(EnumExceptionCode.ThereIsNoStudent.getCode(),EnumExceptionCode.ThereIsNoStudent.getMessage());
        }
        return accountIdByStudentId.getData();
    }
}
